﻿package mortal.game.view.LineOffReward.panel
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import fl.controls.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.LineOffReward.data.*;
    import mortal.game.view.LineOffReward.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.signUp.view.*;
    import mortal.game.view.vip.*;
    import mortal.mvc.core.*;

    public class LineOffRewardCopyPanel extends SignUpViewBase
    {
        public var _copyGetBg:GImageBitmap;
        public var _bg:ScaleBitmap;
        public var _tipTxt1:GTextFiled;
        public var _tipTxt2:GTextFiled;
        public var _tipTxt3:GTextFiled;
        public var _tipTxt4:GTextFiled;
        public var _oneKeyBtn:GLoadingButton;
        public var _extreBtn:GLoadingButton;
        public var _copyList:GTileList;
        public var _cionGetDes:GBitmap;
        public var _goldGetDes:GBitmap;
        protected var _tipTxt:GTextFiled;
        protected var _need1:GTextFiled;
        protected var _need2:GTextFiled;
        protected var _coinTip:GTextFiled;
        protected var _goldTip:GTextFiled;
        public var uiLoadComplete:Boolean = false;
        private var _obj:Object = null;
        private var _objType:int = 1;

        public function LineOffRewardCopyPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.LineOffReward, this.onResLoad);
            return;
        }// end function

        private function onResLoad() : void
        {
            this.uiLoadComplete = true;
            if (this._disposed)
            {
                return;
            }
            this._copyGetBg = UIFactory.gImageBitmap(ImagesConst.LineOffCopyDownBg, 0, 410, this);
            this._tipTxt1 = UIFactory.gTextField("", 117, 481, 200, 20);
            this._tipTxt2 = UIFactory.gTextField("", 118, 506, 250, 20);
            this._bg = UIFactory.bg(0, 0, 696, 404, this, ImagesConst.PanelBg);
            this._tipTxt3 = UIFactory.gTextField("", 383, 481, 250, 20);
            this._tipTxt4 = UIFactory.gTextField("", 384, 506, 250, 20);
            this._oneKeyBtn = UIFactory.gLoadingButton(ImagesConst.LineOffCopyGoldGetBtn_upSkin, 130, 423, 143, 44, this);
            this._oneKeyBtn.label = "";
            this._cionGetDes = UIFactory.gBitmap(ImagesConst.LineOffCopyOneKeyBtnPic, 211, 440);
            this._extreBtn = UIFactory.gLoadingButton(ImagesConst.LineOffCopyVIPGetBtn_upSkin, 408, 423, 143, 44, this);
            this._extreBtn.label = "";
            this._goldGetDes = UIFactory.gBitmap(ImagesConst.LineOffCopyGoldGetBtnPic, 416, 440);
            this._copyList = UIFactory.tileList(7, 4, 670, 390, this);
            this._copyList.scrollPolicy = ScrollPolicy.ON;
            this._copyList.direction = GBoxDirection.VERTICAL;
            this._copyList.setStyle("cellRenderer", LineOffCopyCell);
            this._copyList.verticalGap = 2;
            this._copyList.horizontalGap = 2;
            this._copyList.rowHeight = 130;
            this._copyList.columnWidth = 335;
            this._copyList.columnCount = 2;
            this._copyList.rowCount = 3;
            this._copyList.width = 700;
            this._copyList.drawNow();
            this._tipTxt = UIFactory.gTextField("" + Language.getString(71714), 211, 193, 260, 30, this, GlobalStyle.textFormatPutong.setSize(18).center());
            this._tipTxt.visible = false;
            this._need1 = UIFactory.gTextField("" + Language.getString(71715), 111, 478, 180, 20, this, GlobalStyle.textFormatPutong.center());
            this._need2 = UIFactory.gTextField("" + Language.getString(71716), 346, 478, 270, 40, this, GlobalStyle.textFormatPutong.center());
            this._need2.multiline = true;
            this._need2.wordWrap = true;
            this._coinTip = UIFactory.gTextField("", 102, 502, 200, 20, this, GlobalStyle.textFormatPutong.center());
            this._goldTip = UIFactory.gTextField("", 385, 502, 200, 20, this, GlobalStyle.textFormatPutong.center());
            this._oneKeyBtn.configEventListener(MouseEvent.CLICK, this.onGetCk);
            this._extreBtn.configEventListener(MouseEvent.CLICK, this.onGetCk);
            Dispatcher.dispatchEvent(new DataEvent(EventName.LineOffRewardOnOpenPage));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this.uiLoadComplete == false)
            {
                return;
            }
            this._copyGetBg.dispose(param1);
            this._bg.dispose(param1);
            this._tipTxt1.dispose(param1);
            this._tipTxt2.dispose(param1);
            this._tipTxt3.dispose(param1);
            this._tipTxt4.dispose(param1);
            this._oneKeyBtn.dispose(param1);
            this._extreBtn.dispose(param1);
            this._copyList.dispose(param1);
            this._cionGetDes.dispose(param1);
            this._goldGetDes.dispose(param1);
            this._copyGetBg = null;
            this._bg = null;
            this._tipTxt1 = null;
            this._tipTxt2 = null;
            this._tipTxt3 = null;
            this._tipTxt4 = null;
            this._oneKeyBtn = null;
            this._extreBtn = null;
            this._copyList = null;
            this._cionGetDes = null;
            this._goldGetDes = null;
            this._need1 = null;
            this._need2 = null;
            this._coinTip = null;
            this._goldTip = null;
            this._tipTxt.dispose(param1);
            this._tipTxt = null;
            Cache.instance.lineOff.isOneKeyGet = false;
            return;
        }// end function

        public function initCopy() : void
        {
            var _loc_1:* = Cache.instance.lineOff.freshDate();
            this._copyList.dataProvider = new DataProvider(_loc_1);
            this._copyList.drawNow();
            this.updateGetBtns();
            if (_loc_1.length == 0)
            {
                this._tipTxt.visible = true;
            }
            else
            {
                this._tipTxt.visible = false;
            }
            this.updateTimMoney();
            return;
        }// end function

        public function updateOneCopy(param1:SCopyCompensation) : void
        {
            var _loc_3:SCopyCompensation = null;
            var _loc_4:LineOffCopyCell = null;
            var _loc_2:int = 0;
            while (_loc_2 < this._copyList.dataProvider.length)
            {
                
                _loc_3 = this._copyList.getItemAt(_loc_2) as SCopyCompensation;
                if (_loc_3.copyCode == param1.copyCode)
                {
                    _loc_4 = this._copyList.itemToCellRenderer(_loc_3) as LineOffCopyCell;
                    if (_loc_4)
                    {
                        _loc_4.data = param1;
                    }
                    break;
                }
                _loc_2++;
            }
            this.updateGetBtns();
            return;
        }// end function

        public function updateAllDataProvider(param1:Array) : void
        {
            this._copyList.dataProvider = new DataProvider(param1);
            this._copyList.drawNow();
            this.updateGetBtns();
            this.updateTimMoney();
            return;
        }// end function

        public function freshData() : void
        {
            Cache.instance.lineOff.freshDate();
            this.initCopy();
            return;
        }// end function

        private function updateTimMoney() : void
        {
            var _loc_1:* = this.getAllMoney(1);
            var _loc_2:* = this.getAllMoney(2);
            var _loc_3:* = this.getAllGoinNoGold();
            this._coinTip.text = Language.getStringByParam(71717, _loc_1);
            this._goldTip.text = Language.getStringByParam(71718, _loc_3, _loc_2);
            return;
        }// end function

        private function onGetCk(event:MouseEvent) : void
        {
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_2:int = 1;
            var _loc_3:* = GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitCoin);
            if (this._extreBtn == event.currentTarget)
            {
                _loc_7 = Cache.instance.lineOff.vipType;
                if (VipUtil.isVipReachLevelByType(_loc_7))
                {
                    _loc_2 = 2;
                    _loc_3 = GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitGold);
                }
                else
                {
                    MsgManager.showRollTipsMsg(Language.getStringByParam(71719, VipUtil.getVipMinLevelByType(_loc_7)));
                    return;
                }
            }
            this._obj = {};
            this._objType = _loc_2;
            var _loc_4:* = this.getAllMoney(_loc_2);
            var _loc_5:String = "";
            if (_loc_2 == 2)
            {
                _loc_8 = this.getAllGoinNoGold();
                _loc_5 = _loc_8 + GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitCoin);
                _loc_5 = _loc_5 + ("," + _loc_4 + _loc_3);
                this._obj.num = _loc_8;
            }
            else
            {
                _loc_5 = "" + _loc_4 + _loc_3;
                this._obj.num = _loc_4;
            }
            var _loc_6:* = Language.getStringByParam(71720, _loc_5);
            TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.LineOffGetReward, this.getCallback, _loc_6, null, Alert.OK | Alert.CANCEL);
            return;
        }// end function

        private function getAllMoney(param1:int) : int
        {
            var _loc_6:SCopyCompensation = null;
            var _loc_7:TOfflineCopyCompensate = null;
            var _loc_8:SCopyCompensation = null;
            var _loc_9:int = 0;
            var _loc_2:* = Cache.instance.lineOff.showCopyArr;
            var _loc_3:* = Cache.instance.lineOff.showCopyObj;
            var _loc_4:int = 0;
            if (_loc_2 == null)
            {
                return _loc_4;
            }
            var _loc_5:int = 0;
            while (_loc_5 < _loc_2.length)
            {
                
                _loc_6 = _loc_2[_loc_5];
                if (_loc_6.count > 0)
                {
                    _loc_7 = LineOffRewardConfig.instance.lineOffCopyReward[_loc_6.copyCode];
                    _loc_8 = _loc_3[_loc_7.id];
                    _loc_9 = 0;
                    if (_loc_8)
                    {
                        _loc_9 = int(_loc_8.count);
                    }
                    if (param1 == 1)
                    {
                        _loc_4 = _loc_4 + _loc_7.coin * _loc_9;
                    }
                    else
                    {
                        _loc_4 = _loc_4 + _loc_7.gold * _loc_9;
                    }
                }
                _loc_5++;
            }
            return _loc_4;
        }// end function

        private function getAllGoinNoGold() : int
        {
            var _loc_5:SCopyCompensation = null;
            var _loc_6:TOfflineCopyCompensate = null;
            var _loc_7:SCopyCompensation = null;
            var _loc_8:int = 0;
            var _loc_1:* = Cache.instance.lineOff.showCopyArr;
            var _loc_2:* = Cache.instance.lineOff.showCopyObj;
            var _loc_3:int = 0;
            if (_loc_1 == null)
            {
                return _loc_3;
            }
            var _loc_4:int = 0;
            while (_loc_4 < _loc_1.length)
            {
                
                _loc_5 = _loc_1[_loc_4];
                if (_loc_5.count > 0)
                {
                    _loc_6 = LineOffRewardConfig.instance.lineOffCopyReward[_loc_5.copyCode];
                    _loc_7 = _loc_2[_loc_6.id];
                    _loc_8 = 0;
                    if (_loc_7)
                    {
                        _loc_8 = int(_loc_7.count);
                    }
                    if (_loc_6.gold == 0)
                    {
                        _loc_3 = _loc_3 + _loc_6.coin * _loc_8;
                    }
                }
                _loc_4++;
            }
            return _loc_3;
        }// end function

        private function getCallback() : void
        {
            if (Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitCoinBind, this._obj.num) == false)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShowBindCoinPackWin, this._obj.num));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.LineOffRewardOneKeyGetCopy, this._objType));
            return;
        }// end function

        private function updateGetBtns() : void
        {
            var _loc_4:SCopyCompensation = null;
            var _loc_1:* = Cache.instance.lineOff.showCopyArr;
            var _loc_2:Boolean = false;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_4 = _loc_1[_loc_3];
                if (_loc_4.count > 0)
                {
                    _loc_2 = true;
                    break;
                }
                _loc_3++;
            }
            if (_loc_2)
            {
                this._oneKeyBtn.enabled = true;
                this._oneKeyBtn.filters = null;
                this.checkVIPOneBtn();
            }
            else
            {
                var _loc_5:Boolean = false;
                this._extreBtn.enabled = false;
                this._oneKeyBtn.enabled = _loc_5;
                var _loc_5:* = [FilterConst.colorFilter2];
                this._extreBtn.filters = [FilterConst.colorFilter2];
                this._oneKeyBtn.filters = _loc_5;
            }
            return;
        }// end function

        private function checkVIPOneBtn() : void
        {
            var _loc_1:* = Cache.instance.lineOff.vipType;
            if (VipUtil.isVipReachLevelByType(_loc_1))
            {
                this._extreBtn.enabled = true;
                this._extreBtn.filters = null;
                this._need2.text = "" + Language.getString(71721);
            }
            else
            {
                this._extreBtn.enabled = false;
                this._extreBtn.filters = [FilterConst.colorFilter2];
                this._need2.text = "" + Language.getString(71722);
            }
            return;
        }// end function

    }
}
